package dataobj;

/***
 * Set and return the information of the file path and store name of the files.
 */
public class ConfigTO {

	private static ConfigTO to = null;
	private String filePath;
	private String storePath;
	private String storeName;
	private String defaultStoreName;
	private String university;
	private boolean proceedExceptionDates;

	/***
	 * Class constructor.
	 */
	public ConfigTO() {
		this.defaultStoreName = "calendar";
		setStoreName();
	}

	/***
	 * Return the path of the html file of the calendar.
	 * @return		the file path.
	 */
	public String getFilePath() {
		return filePath == null ? "" : filePath;
	}

	/***
	 * Set the path of the html file of the calendar.
	 * @param filePath	the file path
	 */
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	/***
	 * Return the directory of the generated ICS file.
	 * @return		the directory
	 */
	public String getStorePath() {
		if (storePath==null || storePath.equals("")) {
			return new java.io.File(getFilePath()).getParent();
		} else
			return storePath;
	}

	/***
	 * Return the file path of the generated ICS file
	 * @return		the file path
	 */
	public String getICSLocation() {
		if (getStorePath().contains("\\"))
			return getStorePath() + "\\" + storeName + ".ics";
		else
			return getStorePath() + "//" + storeName + ".ics";
	}

	/***
	 * Set the directory of the generated ICS file.
	 * @param storePath	the directory
	 */
	public void setStorePath(String storePath) {
			this.storePath = storePath;
	}

	/***
	 * Return whether the exception dates are proceed.
	 * @return		the boolean
	 */
	public boolean isProceedExceptionDates() {
		return proceedExceptionDates;
	}

	/***
	 * Set the exception dates are proceed.
	 * @param proceedExceptionDates	the boolean of whether the exception dates are proceed
	 */
	public void setProceedExceptionDates(boolean proceedExceptionDates) {
		this.proceedExceptionDates = proceedExceptionDates;
	}

	/***
	 * Return the store name of the ICS file.
	 * @return		the store name
	 */
	public String getStoreName() {
		return storeName;
	}
	
	/***
	 * Initialize the store name.
	 */
	public void setStoreName(){
		setStoreName("");
	}

	/***
	 * If the store name is not specified by the user, Return the store name as "calendar".
	 * Else, return the user-specified store name.
	 * @param storeName	the store name
	 */
	public void setStoreName(String storeName) {
		if (storeName.equals("")) {
			this.storeName = this.defaultStoreName;
		} else
			this.storeName = storeName;
	}

	/***
	 * Return the university name.
	 * @return		the university name
	 */
	public String getUniversity() {
		return university;
	}

	/***
	 * Set the format of the university name.
	 * @param u_str	the university name
	 * @return		formated university name.
	 */
	public boolean setUniversity(String u_str) {
		try {
			Class.forName("impl." + u_str.toLowerCase() + "Impl");
		} catch (ClassNotFoundException e) {
			university = null;
			return false;
		}

		university = u_str;
		return true;
	}
}
